package com.quxian.chambercommerce.external_action;


import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpSession;

import com.quxian.chambercommerce.base.BaseAction;
import com.quxian.chambercommerce.bean.MemberInfoEntity;
import com.quxian.chambercommerce.bean.ModleEntity;
import com.quxian.chambercommerce.service.LoginService;
import com.quxian.chambercommerce.util.StringUtil;

public class MemberLoginAction extends BaseAction{

	private static final long serialVersionUID = 1253164626342724654L;
	DateFormat format = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss"); 
	private String nowTime;
	private LoginService loginService;
	
	private String company_pic_path;
	private String leader_pic_path;
	private Boolean is_show;
	private int staff_id;
	private String business_scope;
	private String create_time;
	private String company_type;
	private String link;
	private String company_address;
	private String email;
	private String create_datetime;
	private String company_info;
	private String company_name;
	private String native_place;
	private String phone;
	private int title_id;
	private String company_leader;
	private int id;
	
	private ModleEntity modleEntity;
	private MemberInfoEntity memberInfoEntity;
	private String userName;
	private String password;
	private String errorMessage;
	
	public void setLoginService(LoginService loginService) {
		this.loginService = loginService;
	}
	
	public String getNowTime() {
		return nowTime;
	}
	public void setNowTime(String nowTime) {
		this.nowTime = nowTime;
	}
	public ModleEntity getModleEntity() {
		return modleEntity;
	}
	public void setModleEntity(ModleEntity modleEntity) {
		this.modleEntity = modleEntity;
	}
	public MemberInfoEntity getMemberInfoEntity() {
		return memberInfoEntity;
	}
	public void setMemberInfoEntity(MemberInfoEntity memberInfoEntity) {
		this.memberInfoEntity = memberInfoEntity;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public String getErrorMessage() {
		return errorMessage;
	}
	public void setErrorMessage(String errorMessage) {
		this.errorMessage = errorMessage;
	}
	public LoginService getLoginService() {
		return loginService;
	}
	
	public DateFormat getFormat() {
		return format;
	}

	public void setFormat(DateFormat format) {
		this.format = format;
	}

	public String getCompany_pic_path() {
		return company_pic_path;
	}

	public void setCompany_pic_path(String company_pic_path) {
		this.company_pic_path = company_pic_path;
	}

	public String getLeader_pic_path() {
		return leader_pic_path;
	}

	public void setLeader_pic_path(String leader_pic_path) {
		this.leader_pic_path = leader_pic_path;
	}

	public Boolean getIs_show() {
		return is_show;
	}

	public void setIs_show(Boolean is_show) {
		this.is_show = is_show;
	}

	public int getStaff_id() {
		return staff_id;
	}

	public void setStaff_id(int staff_id) {
		this.staff_id = staff_id;
	}

	public String getBusiness_scope() {
		return business_scope;
	}

	public void setBusiness_scope(String business_scope) {
		this.business_scope = business_scope;
	}

	public String getCreate_time() {
		return create_time;
	}

	public void setCreate_time(String create_time) {
		this.create_time = create_time;
	}

	public String getCompany_type() {
		return company_type;
	}

	public void setCompany_type(String company_type) {
		this.company_type = company_type;
	}

	public String getLink() {
		return link;
	}

	public void setLink(String link) {
		this.link = link;
	}

	public String getCompany_address() {
		return company_address;
	}

	public void setCompany_address(String company_address) {
		this.company_address = company_address;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getCreate_datetime() {
		return create_datetime;
	}

	public void setCreate_datetime(String create_datetime) {
		this.create_datetime = create_datetime;
	}

	public String getCompany_info() {
		return company_info;
	}

	public void setCompany_info(String company_info) {
		this.company_info = company_info;
	}

	public String getCompany_name() {
		return company_name;
	}

	public void setCompany_name(String company_name) {
		this.company_name = company_name;
	}

	public String getNative_place() {
		return native_place;
	}

	public void setNative_place(String native_place) {
		this.native_place = native_place;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public int getTitle_id() {
		return title_id;
	}

	public void setTitle_id(int title_id) {
		this.title_id = title_id;
	}

	public String getCompany_leader() {
		return company_leader;
	}

	public void setCompany_leader(String company_leader) {
		this.company_leader = company_leader;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String login() {
		try{
			if(StringUtil.isEmpty(userName)) {
				return ERROR;
			}
			
			if(StringUtil.isEmpty(password)) {
				return ERROR;
			}
//			password = ThreeDES.getEncString(password);
			memberInfoEntity = loginService.memberLogin(userName, password);
			Date mdate = new Date();
			nowTime = format.format(mdate);
			
			HttpSession session = request.getSession();
			session.setAttribute("user",memberInfoEntity);
			
		} catch (Exception e) {
			e.printStackTrace();
			
			errorMessage = e.getMessage();
			return ERROR;
		}
		return SUCCESS;
	}
	
	public String registerMember(){
		try {
			MemberInfoEntity entity = new MemberInfoEntity();
			entity.setCompany_pic_path(company_pic_path);
			entity.setLeader_pic_path(leader_pic_path);
			entity.setIs_show(is_show);
			entity.setStaff_id(staff_id);
			entity.setPassword(password);
			entity.setUser_name(userName);
			entity.setBusiness_scope(business_scope);
			entity.setCreate_time(create_time);
			entity.setCompany_type(company_type);
			entity.setLink(link);
			entity.setCompany_address(company_address);
			entity.setEmail(email);
			entity.setCreate_datetime(create_datetime);
			entity.setCompany_info(company_info);
			entity.setCompany_name(company_name);
			entity.setNative_place(native_place);
			entity.setPhone(phone);
			entity.setTitle_id(title_id);
			entity.setCompany_leader(company_leader);
			int memberId = loginService.registerMember(entity);
			
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
		}
		return SUCCESS;
		
	}
}
